﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// visit_log 的摘要说明
    /// </summary>
    public class visit_log : IHttpHandler, IRequiresSessionState
    {
        /// <summary>
        /// 手机企业店铺每天点击次数
        /// 关键词每天搜索次数
        /// 全国轮播大图每天查看次数
        /// 日活跃用户数
        /// </summary>

        public void ProcessRequest(HttpContext context)
        {
            StringBuilder strTxt = new StringBuilder();
            //context.Response.ContentType = "text/plain";
            int _txtUserID = DTRequest.GetQueryInt("txtUserID");
          
            int _object_type = DTRequest.GetQueryInt("txtobject_type");//访问类型  
            int _object_id = DTRequest.GetQueryInt("txtobject_id");//访问实体的ID 黄页 ID  或者大图轮播ID
            string _keywords = DTRequest.GetString("txtkeywords");//访问内容  比如 关键词搜索，每日登录或其他操作
            string _longitude = DTRequest.GetString("txtlongitude");//经度
            string _latitude = DTRequest.GetString("txtlatitude");//纬度
            string _systemtype = DTRequest.GetString("txtsystemtype");//系统类型 ios 或andriod

            string logmsg = "";
            string _object_typetxt = "";
            try
            {
                BLL.dt_user_visit_log logbll = new BLL.dt_user_visit_log();
                Model.dt_user_visit_log logmodel = new Model.dt_user_visit_log();
                #region 会员部分判断
                logmodel.user_id = _txtUserID;

                #endregion
                //类型为关键词或者活跃用户的时候 object_id 值为0
                if (_object_type == 2 || _object_type == 4) { _object_id = 0; }

                #region 类型对应文本
                if (_object_type == 1) { _object_typetxt = "手机企业店铺每天点击次数"; }
                else if (_object_type == 2) { _object_typetxt = "关键词每天搜索次数"; }
                else if (_object_type == 3) { _object_typetxt = "全国轮播大图每天查看次数"; }
                else if (_object_type == 4) { _object_typetxt = "日活跃用户数"; }
                #endregion
                logmodel.object_type = _object_type;
                logmodel.object_id = _object_id;
                logmodel.latitude = _latitude;
                logmodel.longitude = _longitude;
                logmodel.ip = DTRequest.GetIP();
                logmodel.systemtype = _systemtype;
                logmodel.addtime = DateTime.Now;
                logmodel.keywords = _keywords;
                logmodel.title = _object_typetxt;
                logmodel.con = logmsg;
                logbll.Add(logmodel);
                context.Response.Write("{\"status\":1, \"msg\":\"success！\"}");
            }
            catch (Exception ex) { context.Response.Write("{\"status\":0, \"msg\":\"错误提示：" + ex.Message + "！\"}"); }


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}